package com.ruoyi.oar.api.util;

import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.ToolUtil;
import com.ruoyi.oar.dto.PortraitcomparisonResult;

import java.util.Map;

/**
 * @Description: 调用车服api
 * @Author: LJ
 * @Date: 2021/12/28 13:50
 * @version:
 */
public class CarHttpUtil {
    /**
     * 统一接口
     */
    public static final String PATH = "/interface/interfOpt";

    /**
     * 调用车服三要素接口进行核验
     *
     * @param map 参数
     * @return
     */
    public static Integer checkPortraitcomparison(Map<String, Object> map) {
        //调用三要素接口查询
        PortraitcomparisonResult result = CarServiceUtil
                .getData(map, "413", PATH)
                .getJSONArray("IDCARD_PORTRAITCOMPARISONLIST")
                .toJavaList(PortraitcomparisonResult.class).get(0);

        if (!"1".equals(result.getSearchState())) {
            return 0;
//            throw new ServiceException("人证核验失败," + (ToolUtil.isEmpty(result.getStateDesc()) ? "请重试" : result.getStateDesc()));
        } else if (!"一致".equals(result.getResultGmsfhm()) || !"一致".equals(result.getResultXm())) {
//            throw new ServiceException("人证核验失败,姓名和身份证不匹配");
            return 0;
        } else if (ToolUtil.isNotEmpty(result.getResultFs()) && Integer.parseInt(result.getResultFs()) < 60) {
//            throw new ServiceException("人像核验不通过，请重新尝试");
            return 0;
        }
        return 1;
    }
}
